package dk.itu.iwjx.helper;


import java.util.Comparator;
import dk.itu.iwjx.beans.PizzaBean;

public class SortCriteria implements Comparator<PizzaBean>{
	private String sortBy;
	
	public SortCriteria(String sortBy){
		this.sortBy=sortBy;
	}
	
	@Override
	public int compare(PizzaBean o1, PizzaBean o2) {
		//compare by price
		if(sortBy.equals("price")){
			if(((PizzaBean)o1).getPrice()>((PizzaBean)o2).getPrice())return 1;
			if(((PizzaBean)o1).getPrice()<((PizzaBean)o2).getPrice())return -1;
		}
		
		//compare by name
		if(sortBy.equals("name")){
			return ((PizzaBean)o1).getName().compareTo(((PizzaBean)o2).getName());
		}
		return 0;
	}
}
